﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using DeSleeper.Client.Properties;
using DeSleeper.Client.WakeUp;
using MbUnit.Framework;
using MbUnit.Framework.Xml;

namespace DeSleeper.Tests
{
    class ProxyWakeUpDestinationFixture
    {
        [Test]
        public void LoadAndSaveFromSettings()
        {
            var expected = new ProxyWakeUpDestination { ProxyAddress = "TestAddress" };
            WakeUpDestination.All.Add(expected);
            Settings.Default.Save();
            Settings.Default.Reload();
            Assert.IsNotNull(Settings.Default.Destinations);
            var result = WakeUpDestination.All.Last() as ProxyWakeUpDestination;
            Assert.AreEqual(expected.ProxyAddress, result.ProxyAddress);
        }

        [Test]
        public void SerializeDestination()
        {
            var expected = new ProxyWakeUpDestination { ProxyAddress = "TestAddress" };
            var serializer = new XmlSerializer(typeof(ProxyWakeUpDestination));

            using (var writer = new StringWriter())
            {
                serializer.Serialize(writer, expected);
                using (var reader = new StringReader(writer.GetStringBuilder().ToString()))
                {
                    var output = serializer.Deserialize(reader) as ProxyWakeUpDestination;
                    Assert.AreEqual(expected.ProxyAddress, output.ProxyAddress);
                }
            }
        }

        [Test]
        public void Set()
        {
            var destination = new ProxyWakeUpDestination();
            string expected = "Test";
            destination.ProxyAddress = expected;
            Assert.AreEqual(expected, destination.ProxyAddress);
        }
    }
}
